package utils;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import data.wg.AbstractWoTCWBotListEntity;



public class Utils 
{

	public static String convertStreamToString(java.io.InputStream is) {
	    java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
	    return s.hasNext() ? s.next() : "";
	}
	
	public static void unmarkAll(List<? extends AbstractWoTCWBotListEntity> asd)
	{
		for(AbstractWoTCWBotListEntity ae :asd)
		{
			ae.marked=false;
		}
	}
	
	public static <T extends Markable> List<T> removeUnmarked(List<T> asd)
	{
		List<T> newlist = new ArrayList<T>();
		for(T ae :asd)
		{
			if(ae.isMarked()){
				newlist.add(ae);
			}
		}
		return newlist;
	}
	
	/**
	 * This Methode uses .equals to determine wether the two given lists are identical.
	 * @param a
	 * @param b
	 * @return
	 */
	public static <T extends Comparable<T>>  boolean listsAreEqual(List<T> a, List<T>b)
	{
		if(a.size()!=b.size())
		{
			return false;
		}
		for(int i=0;i<a.size();i++)
		{
			Object o = Utils.findInListByEquals(a.get(i), b);
			if(o==null)
			{
				return false;
			}
		}
		return true;
	}
	
	public static <T> T findInListByEquals(T o, List<T> l)
	{
		for(T p:l)
		{
			if(o.equals(p))
			{
				return p;
			}
		}
		return null;
	}
	
	public static String getDateString(long ms)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
		
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(ms*1000);
		
		return sdf.format(c.getTime());
	}
}
